﻿using System;
using System.Web.UI.WebControls;
using Bingosoft.Core;
using Bingosoft.Modules.SecurityConsole.Privilege;

namespace Bingosoft.WebApp.Modules.SecurityConsole.Privilege
{
    public partial class OperationRuleList : System.Web.UI.BasePage
    {
        private PrivilegeService _privilegeService;
        private PrivilegeService PrivilegeService
        {
            get
            {
                return _privilegeService ??
                       (_privilegeService = App.Current.GetObjectContainer().GetObject("PrivilegeService") as PrivilegeService);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            // 只有控制页面元素时才需要显示元素行为
            SmartGridView1.Columns[4].Visible = !String.IsNullOrEmpty(Request.Params["ElementId"]);
        }

        protected void SearchGrid(object sender, EventArgs e)
        {
            SmartGridView1.PageIndex = 0;
            SmartGridView1.DataBind();
        }

        protected void RefreshGrid(object sender, EventArgs e)
        {
            SmartGridView1.DataBind();
        }

        protected void DeletePermissionRule(object sender, EventArgs e)
        {
            String permissionRuleId = ((ImageButton)sender).Attributes["_KeyId"];
            this.PrivilegeService.DeletePermissionRule(permissionRuleId);
            SmartGridView1.DataBind();
        }

        protected  void DeletePermissionRules(object sender, EventArgs e)
        {
            string[] ruleIds = SmartGridView1.GetCheckedValues();
            this.PrivilegeService.DeletePermissionRules(ruleIds);
            this.SmartGridView1.DataBind();
        }
    }
}